

\documentclass{article}
\usepackage{pgfplots}
\usepackage{ctex}
\pgfplotsset{compat=1.17} % 适配最新版本pgfplots

\begin{document}
	\begin{tikzpicture}
		\begin{axis}[
			% 核心：极简坐标轴（仅显示x/y轴线，无外框）
			axis lines=middle, % 仅显示x轴（水平中线）和y轴（垂直中线）
			axis line style={thick, -latex}, % 轴线加粗+箭头
			% 坐标轴范围设置（根据函数和采样点分布优化）
			xmin=0, xmax=9,
			ymin=-6, ymax=5,
			% 坐标轴标签
			xlabel={$x$},
			ylabel={$f(x)$},
			% 标题（说明函数类型和采样点）
			title={8次插值函数及其9个采样点},		
			% 坐标轴刻度优化
			xtick={0,1,2,3,4,5,6,7,8,9}, % x轴刻度与采样点x坐标对应
			ytick={-5,-4,-3,-2,-1,0,1,2,3,4,5},
			% 图例位置（避免遮挡函数曲线）
			legend pos=north west,
			% 标题和标签字体大小
			title style={font=\large},
			label style={font=\large},
			tick label style={font=\large},
			smooth cycle
			]
			
			% 绘制8次插值函数曲线（蓝色实线，线宽加粗）
				% 1. 区间[1,2]：-0.26804123711340205x³ + 1.268041237113402x + 1
			\addplot[blue, thick, domain=1:2,smooth] {
				-0.26804123711340205*x^3 + 1.268041237113402*x + 1
			};
			
			% 2. 区间[2,3]：-0.6597938144329897x³ - 0.8041237113402062x² + 0.463917525773196x + 2
			\addplot[blue, thick, domain=2:3,smooth] {
				-0.6597938144329897*x^3 - 0.8041237113402062*x^2 + 0.463917525773196*x + 2
			};
			
			% 3. 区间[3,4]：2.9072164948453607x³ - 2.783505154639175x² - 3.1237113402061856x + 1
			\addplot[blue, thick, domain=3:4,smooth] {
				2.9072164948453607*x^3 - 2.783505154639175*x^2 - 3.1237113402061856*x + 1
			};
			
			% 4. 区间[4,5]：-2.9690721649484533x³ + 5.9381443298969065x² + 0.030927835051546726x - 2
			\addplot[blue, thick, domain=4:5,smooth] {
				-2.9690721649484533*x^3 + 5.9381443298969065*x^2 + 0.030927835051546726*x - 2
			};
			
			% 5. 区间[5,6]：0.9690721649484534x³ - 2.9690721649484533x² + 3.0x + 1
			\addplot[blue, thick, domain=5:6,smooth] {
				0.9690721649484534*x^3 - 2.9690721649484533*x^2 + 3.0*x + 1
			};
			
			% 6. 区间[6,7]：-0.9072164948453607x³ - 0.06185567010309301x² - 0.030927835051546282x + 2
			\addplot[blue, thick, domain=6:7,smooth] {
				-0.9072164948453607*x^3 - 0.06185567010309301*x^2 - 0.030927835051546282*x + 2
			};
			
			% 7. 区间[7,8]：2.6597938144329896x³ - 2.783505154639175x² - 2.8762886597938144x + 1
			\addplot[blue, thick, domain=7:8,smooth] {
				2.6597938144329896*x^3 - 2.783505154639175*x^2 - 2.8762886597938144*x + 1
			};
			
			% 8. 区间[8,9]：-1.731958762886598x³ + 5.195876288659794x² - 0.463917525773196x - 2
			\addplot[blue, thick, domain=8:9,smooth] {
				-1.731958762886598*x^3 + 5.195876288659794*x^2 - 0.463917525773196*x - 2
			};
			
			% 标注9个采样点（红色实心圆，大小放大）
			\addplot[
			red,
			mark=*,
			mark size=4pt, % 点的大小
			only marks % 只显示点，不绘制连线
			] coordinates {
				(1,1)  % 采样点1: (0,1)
				(2,2)  % 采样点2: (1,2)
				(3,1)  % 采样点3: (2,1)
				(4,-2) % 采样点4: (3,-2)
				(5,1)  % 采样点5: (4,1)
				(6,2)  % 采样点6: (5,2)
				(7,1)  % 采样点7: (6,1)
				(8,-2) % 采样点8: (7,-2)
				(9,1)  % 采样点9: (8,1)
			};
			
			
			% （可选）为每个采样点添加坐标标签（避免重叠，微调位置）
		\end{axis}
	\end{tikzpicture}
\end{document}